package com.sxu.threadlocal;

/**
 * 使用synchronized
 */
public class MyDemo03 {
    private String content;

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public static void main(String[] args) {
        MyDemo03 demo = new MyDemo03();
        for (int i = 0; i < 5; i++) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    synchronized (MyDemo03.class) {
                        demo.setContent(Thread.currentThread().getName() + "的数据");
                        System.out.println("---------------------------");
                        System.out.println(Thread.currentThread().getName() + "---->" + demo.getContent());
                    }
                }
            });
            thread.setName("Thread " + i);
            thread.start();
        }
    }
}
